package org.finalministry.logger;

public enum LogLevel {

   OFF("OFF", 2147483647),
   ERROR("ERROR", 40000),
   FATAL("ERROR", 40000),
   WARN("WARN", 30000),
   INFO("INFO", 20000),
   CONFIG("INFO", 20000),
   DEBUG("DEBUG", 10000),
   TRACE("TRACE", 5000),
   ALL("ALL", -2147483648),
   FINE("DEBUG", 10000),
   FINEST("TRACE", 5000),
   FINER("DEBUG", 10000),
   ENTER("TRACE", 5000),
   DURATION("TRACE", 5000),
   EXIT("TRACE", 5000);

   private final String name;

   private final int intLevel;

   public String getName() {

      return name;
   }

   public int getIntLevel() {

      return intLevel;
   }

   private LogLevel(final String name, final int intLevel) {

      this.name = name;
      this.intLevel = intLevel;
   }

   public static LogLevel findByName(final String name) {

      for (LogLevel logLevel : LogLevel.values()) {
         if (logLevel.getName().equals(name)) {
            return logLevel;
         }

      }
      return null;
   }

   public static LogLevel findByNumber(final int number) {

      for (LogLevel logLevel : LogLevel.values()) {
         if (logLevel.getIntLevel() == number) {
            return logLevel;
         }
      }
      return null;
   }
}
